<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学期课题列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" >
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" >
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                    <i class="fa fa-remove"></i> 删除
                </a>
                <button type="button" class="btn btn-warning" onclick="generate()">当前学期实践环节</button>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/term";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "学期课题",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'termId',
                    title: '学期序号',
                    visible: false
                },
                {
                    field: 'termName',
                    title: '学期名字'
                },
                {
                    field: 'termTask1',
                    title: '课题一'
                },
                {
                    field: 'termTask2',
                    title: '课题二'
                },
                {
                    field: 'termTask3',
                    title: '课题三'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.termId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.termId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function generate() {
            $.modal.confirm('确认生成当前学期实践环节吗？',function(){
                var config = {
                    type: "post",
                    url: "/system/term/generate",
                    dataType: "json",
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍后...");
                    },
                    success: function (result) {

                        if (result.msg == "操作失败") {
                            $.modal.alertWarning("已经存在当前学期实践环节，请联系管理员进行数据修改");
                        }
                        else{
                            $.modal.alertSuccess(result.msg);
                        }
                        $.modal.closeLoading();
                    }
                };
                $.ajax(config);
            });
        }
    </script>
</body>
</html>
